package com.ymatou.iapi.m.couponservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.m.couponservice.parameter.QuerySendFailDetailBean;
import com.ymatou.iapi.m.couponservice.parameter.SendRecordInfo;
import com.ymatou.iapi.m.couponservice.service.QuerySendFailDetailCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.YmtCouponSendRecord;
import com.ymttest.database.sqlwapper.YmtCouponSendRecordWapper;
/**
*查询发放失败明细用例
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QuerySendFailDetail{
	private static QuerySendFailDetailBean querysendfaildetailBean;
	private static QuerySendFailDetailCall querysendfaildetailCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询发放失败明细用例");
	}

	@Before
	public void caseUp() {
		querysendfaildetailBean=new QuerySendFailDetailBean();
		querysendfaildetailCall=new QuerySendFailDetailCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querysendfaildetailCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySendFailDetail_001() {
		Logger.start(true,"正例-查询发放失败明细");
		try {
	
			List<YmtCouponSendRecord> records = new YmtCouponSendRecordWapper().selectTop1SendFailRecord();
			
			Logger.verifyEquals(true, records.size()>0, "验证数据库中有发放失败的记录");
			
			querysendfaildetailBean.setTaskId(records.get(0).getTaskId());     
		
			querysendfaildetailCall.setData(querysendfaildetailBean);
			querysendfaildetailCall.callService();	
			
			Logger.verifyEquals("0", querysendfaildetailCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", querysendfaildetailCall.getMessage(), "验证返回Message");
			
			List<YmtCouponSendRecord> results = new YmtCouponSendRecordWapper().selectSendFailRecord(records.get(0).getTaskId());

			List<SendRecordInfo> returns = querysendfaildetailCall.getFailSendRecordList().getFailSendRecordList();
			
			for(int i=0;i<returns.size();i++)
			{
				Logger.verifyEquals(results.get(i).getUserId(), returns.get(i).getUserId(), "验证返回UserId与数据库一致");
				Logger.verifyEquals(results.get(i).getFailReason().intValue(), returns.get(i).getSendFailReason(), "验证返回SendFailReason与数据库一致");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}